package com.meixiang.activity.account.myShopper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.meixiang.R;
import com.meixiang.global.GlobalType;
import com.meixiang.main.BaseActivity;
import com.meixiang.main.MXApplication;
import com.meixiang.util.AbStrUtil;
import com.meixiang.view.photoSelectActivity.activity.PhotoShowFileActivity;
import com.meixiang.view.photoSelectActivity.adapter.ImageFileAdapter;
import com.meixiang.view.photoSelectActivity.util.AlbumHelper;
import com.meixiang.view.photoSelectActivity.util.ImageBucket;
import com.meixiang.view.photoSelectActivity.util.ImageItem;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：黑哥 on 2016/5/13 12:00
 * <p/>
 * 图片文件列表
 */
public class PhotoFileEvaluateActivity extends BaseActivity {

    @Bind(R.id.rv_recycler)
    RecyclerView mRecycler;
    private ImageFileAdapter mAdapter;
    private ArrayList<ImageItem> dataList;
    private AlbumHelper helper;
    public static List<ImageBucket> contentList;
//    private String type;
    private int selectImageSize;

    private ArrayList<String> fileName;
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_image_file);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }
    @Override
    protected void initTitle() {
        setTitle("相册选择");
    }

    @Override
    protected void initView() {
//        type=getIntent().getStringExtra("photoType");
        selectImageSize=getIntent().getIntExtra("selectImageSize",0);
        helper = AlbumHelper.getHelper();
        helper.init(getApplicationContext());
        //数据给处理
        contentList = helper.getImagesBucketList(false);
        dataList = new ArrayList<ImageItem>();
        for (int i = 0; i < contentList.size(); i++) {
            dataList.addAll(contentList.get(i).imageList);
        }

        mAdapter = new ImageFileAdapter(context,contentList);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
        mRecycler.setLayoutManager(layoutManager);
        mRecycler.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new ImageFileAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                ImageBucket bean = contentList.get(position);
                Intent intent =new Intent(context,PhotoShowFileEvaluateActivity.class);
                String folderName = contentList.get(position).bucketName;
                intent.putExtra("folderName", folderName);
                intent.putParcelableArrayListExtra("list", (ArrayList<? extends Parcelable>) contentList.get(position).imageList);
//                intent.putExtra("photoType",type);
                intent.putExtra("selectImageSize",selectImageSize);
                intent.putExtra("position",getIntent().getIntExtra("position",0));
                if(fileName!=null&&fileName.size()>0){
                    intent.putExtra("fileName", fileName);
                }
                startActivityForResult(intent,100);
            }
        });

    }

    @Override
    protected void setData() {

    }

    @Override
    public void onClick(View v) {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode==100&&resultCode==200){
            fileName= data.getStringArrayListExtra("fileName");
            Intent intent=new Intent(this, OrderEvaluationActivity.class);
            intent.putExtra("position",data.getIntExtra("position",0));
            intent.putExtra("fileName",data.getStringArrayListExtra("fileName"));
            setResult(200,intent);
            if(("back").equals(data.getStringExtra("type"))){
                return;
            }
            this.finish();
        }
    }
}
